package com.mjh.comm;

import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class DBInstance {

	private static DBInstance instance = new DBInstance();
	
	private SqlSessionFactory sessionFactory;
	
	private DBInstance(){
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		Reader reader  = null; 
		try {
			reader = Resources.getResourceAsReader("sqlmapconfig.xml");
		} catch (IOException e) {
			e.printStackTrace();
		}
		sessionFactory = builder.build(reader);
	}
	
	public static DBInstance getInstance(){
		return instance;
	}
	
	public SqlSessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	public SqlSession getSession(){
		return sessionFactory.openSession();
	}
	
	public static void main(String[] args) {
		DBInstance.getInstance().getSession();
	}
}
